﻿// Write methods that calculate the surface of a triangle by given:
// - Side and an altitude to it; 
// - Three sides; 
// - Two sides and an angle between them.
// Use System.Math.

namespace _04.CalcTriangleSurface
{
    using System;
    using System.Globalization;
    using System.Threading;

    public class CalcTriangleSurface
    {
        private static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Console.WriteLine("Calculate Triangle Surface:");
            Console.WriteLine(new string('=', 27));
            Console.WriteLine("1. Side and an Side Altitude");
            Console.WriteLine("2. Three sides");
            Console.WriteLine("3. Two sides and an angle between them");
            Console.WriteLine();

            byte choice;
            do
            {
                Console.Write("Enter your choice: ");
            }
            while (!byte.TryParse(Console.ReadLine(), out choice) || choice < 1 || choice > 3);

            Triangle triangle;
            switch (choice)
            {
                case 1:
                    triangle = new Triangle(
                        ConsoleInput("Side A"),
                        ConsoleInput("Side B"));
                    break;
                case 2:
                    triangle = new Triangle(
                        ConsoleInput("Side A"),
                        ConsoleInput("Side B"),
                        ConsoleInput("Side C"),
                        TriangleInputType.SideC);
                    break;
                case 3:
                    triangle = new Triangle(
                        ConsoleInput("Side A"),
                        ConsoleInput("Side B"),
                        ConsoleInput("Angle C"),
                        TriangleInputType.Angle);
                    break;
                default:
                    throw new NotImplementedException("Side Add as needed");
            }

            Console.WriteLine(triangle.ToString());
        }

        private static double ConsoleInput(string sideKind)
        {
            double side;
            do
            {
                Console.Write("Enter {0}: ", sideKind);
            }
            while (!double.TryParse(Console.ReadLine().Replace(",", "."), out side));

            return side;
        }
    }
}